<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *会员日志
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';

$tabs=array(
			array('op'=>'list','title'=>'日志列表'),
);
//会员日志
if($_RQ['op']=='list'){
	$params=array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid']);
	if(!empty($_RQ['workerid'])){
		$params['workerid']=intval($_RQ['workerid']);
		$return['params']['workerid']=intval($_RQ['workerid']);
	}
	if(!empty($_RQ['userid'])){
		$params['userid']=intval($_RQ['userid']);
		$return['params']['userid']=intval($_RQ['userid']);
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_scrm_worker_linelog',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['member']=pdo_get('jy_scrm_member',array('id'=>$item['userid'],'uniacid'=>$_SESSION['uniacid']));
			$item['worker']=pdo_get('jy_scrm_worker',array('id'=>$item['workerid'],'uniacid'=>$_SESSION['uniacid']));
			$item['member']=array('nickname'=>$item['member']['name'],'avatar'=>$item['member']['avatar'],'mobile'=>$item['member']['corp_name']);
		}
	}
	
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>true,'del_one'=>true,'delall'=>true,'list'=>array(
			array('type'=>'img_string','title'=>'员工信息','img'=>'worker.avatar',
			'data'=>array(
				array('title'=>'','name'=>'worker.name'),
				array('title'=>'职位：','name'=>'worker.position')
				)
			),
			array('name'=>'member','title'=>'客户信息','type'=>'member'),
			array('name'=>'content','title'=>'日志内容','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
			array('name'=>'createtime','title'=>'时间','type'=>'time'),
		)),
		'search'=>array(
			array('type'=>'choose','width'=>13,'title'=>'选择员工','name'=>'workerid','action'=>'jy_merchscrm/merch.worker.get_worker/'),
			array('type'=>'choose','width'=>13,'title'=>'选择客户','name'=>'userid','action'=>'jy_merchscrm/merch.member.get_member/'),
		)
	);
	$return['status']=$this->linelog_status;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
	$return=array();
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_scrm_worker_linelog',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		
	}else{
		$item=array();
	}
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回日志列表'),
		),
		'edit_tab'=>true,
		'edits'=>array(
			array(
				'title'=>'基本信息',
				'list'=>array(
					array('type'=>'string','title'=>'日志名称','name'=>'title','help'=>''),
					array('type'=>'switch','title'=>'状态','name'=>'status','help'=>''),
					
				)
			),
		)
	);
	
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(!$postdata['title']){
		exi('请填写标签名称',true);
	}
	$data=array(
		'title'=>trim($postdata['title']),
		'status'=>trim($postdata['status']),
	);
	$id=intval($postdata['id']);
	if($id){
		pdo_update('jy_scrm_worker_linelog',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['merchid']=$_SESSION['onemerchid'];
		pdo_insert('jy_scrm_worker_linelog',$data);
	}
	exi('操作成功！','','list');
}
if($_RQ['op']=='set'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择用户组！','error');
	}
	$post=get_postdata();
	if(isset($post['status'])){
		pdo_update('jy_scrm_worker_linelog',array('status'=>intval($post['status'])),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	exi('操作成功！');
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_scrm_worker_linelog',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}